package com.demo.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResultJson implements Serializable {

    private boolean success = true;
    private String code = "";
    private String msg = "";
    private Object data;

    public static String ok(Object data) {
        ResultJson resultJson = new ResultJson();
        resultJson.data = data;
        return JSONObject.toJSONString(resultJson);
    }

    public static String fail(String errCode) {
        ResultJson resultJson = new ResultJson();
        resultJson.success = false;
        resultJson.code = errCode;
        resultJson.msg = errCode;
        return JSONObject.toJSONString(resultJson);
    }

    public ResultJson() {
    }

}
